package com.lehecai.core.api.business;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.lottery.WalletType;
import com.lehecai.core.util.CoreDateUtils;

/**
 * 语音汇款限额
 * @author He Wang
 *
 */
public class VoiceRechargeAmount extends AbstractApiResultBean {

    public static final String QUERY_ID = "uid";
    public static final String QUERY_IDS = "uids";
    public static final String QUERY_WALLET_TYPE = "wallet_type";
    public static final String QUERY_USER_NAME = "username";
    public static final String QUERY_STATUS = "status";
    
    public static final String SET_WALLET_TYPE = "wallet_type";
    public static final String SET_USER_NAME = "username";
    public static final String SET_AMOUNT = "amount";
    public static final String SET_STATUS = "status";

    private Long id;                     	    //uid
    private WalletType walletType;              //钱包类型
    private Date createdTime;                   //创建时间
    private Date updateTime;                    //更新时间
    private Double amount;                      //金额
    private String userName;                    //用户名
    private YesNoStatus status;                 //是否使用额度限制

    public static VoiceRechargeAmount convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        VoiceRechargeAmount voiceRechargeAmount = new VoiceRechargeAmount();
        
        voiceRechargeAmount.setId(getLong(object, "uid"));
        voiceRechargeAmount.setWalletType(WalletType.getItem(Integer.valueOf(getString(object, QUERY_WALLET_TYPE))));
        voiceRechargeAmount.setUserName(getString(object, QUERY_USER_NAME));
        voiceRechargeAmount.setCreatedTime(CoreDateUtils.parseDate(getString(object, "create_time"), CoreDateUtils.DATETIME));
        voiceRechargeAmount.setUpdateTime(CoreDateUtils.parseDate(getString(object, "update_time"), CoreDateUtils.DATETIME));
        voiceRechargeAmount.setAmount(Double.valueOf(getString(object, SET_AMOUNT)));
        voiceRechargeAmount.setStatus(YesNoStatus.getItem(Integer.valueOf(getString(object, QUERY_STATUS))));
        
        return voiceRechargeAmount;
    }

    public static List<VoiceRechargeAmount> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<VoiceRechargeAmount> list = new ArrayList<VoiceRechargeAmount>();

        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }


	public void setWalletType(WalletType walletType) {
		this.walletType = walletType;
	}

	public WalletType getWalletType() {
		return walletType;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public Double getAmount() {
		return amount;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserName() {
		return userName;
	}

	public void setStatus(YesNoStatus status) {
		this.status = status;
	}

	public YesNoStatus getStatus() {
		return status;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

}
